<!--考核模板-->
<template>
	<el-card>
		<el-form :inline="true" :model="state.queryForm" @keyup.enter="getDataList()">
			<el-form-item class="form-button-right">
				<el-button v-auth="'attendance:shift:save'" type="primary" @click="addOrUpdateHandle()">新增模板</el-button>
				<el-button v-auth="'attendance:shift:save'" type="primary" @click="addOrUpdateHandle()">批量删除指标</el-button>
			</el-form-item>

			<el-form-item>
				<KeyQuery v-model="state.queryForm.keyword" @getDataList="getDataList()" />
			</el-form-item>
		</el-form>
		
		<el-row>
			<el-col :span="4">
				<el-table
					v-if="refreshTable"
					:default-expand-all="true"
					v-loading="state.dataListLoading"
					:data="dataListLeft.dataList"
					row-key="id"
					class="left-tree"
					:cell-style="{ borderColor: '#00000000' }"
					:header-cell-style="{ borderColor: '#00000000' }"
					@row-click="fnRoleId"
				>
					<el-table-column prop="name" label="模板类别" header-align="center" align="center"></el-table-column>

					<el-table-column label="操作" fixed="right" header-align="right" align="right" width="150" :render-header="addLeftView">
						<template #default="scope">
							<div class="operation_show">
								<el-button v-auth="'module:role:update'" type="primary" link @click="addOrUpdateHandle(scope.row.id)">编辑</el-button>
								<el-button v-auth="'module:role:delete'" type="primary" link @click="deleteBatchHandle(scope.row.id)">删除</el-button>
							</div>
						</template>
					</el-table-column>
				</el-table>
			</el-col>
			<el-col :span="20">
				<el-table v-loading="state.dataListLoading" :data="state.dataList" border style="width: 100%" @selection-change="selectionChangeHandle">
					<el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
					<el-table-column prop="id" label="主键" header-align="center" align="center" v-if="false"></el-table-column>

					<el-table-column prop="name" label="模板名称" header-align="center" align="center"></el-table-column>
					<el-table-column prop="code" label="考核周期" header-align="center" align="center"></el-table-column>
					<el-table-column prop="phone" label="考核类型" header-align="center" align="center"></el-table-column>
					<el-table-column prop="organName" label="核算方式" header-align="center" align="center"></el-table-column>
					<el-table-column prop="positionName" label="备注" header-align="center" align="center"></el-table-column>

					<el-table-column label="操作" fixed="right" header-align="center" align="center" width="250">
						<template #default="scope">
							<el-button v-auth="'module:workplace:update'" type="primary" link @click="deleteBatchHandle(scope.row.id)">编辑</el-button>
							<el-button v-auth="'module:workplace:update'" type="primary" link @click="deleteBatchHandle(scope.row.id)">删除</el-button>
						</template>
					</el-table-column>
				</el-table>

				<el-pagination
					:current-page="state.page"
					:page-sizes="state.pageSizes"
					:page-size="state.limit"
					:total="state.total"
					layout="total, sizes, prev, pager, next, jumper"
					@size-change="sizeChangeHandle"
					@current-change="currentChangeHandle"
				>
				</el-pagination>
			</el-col>
		</el-row>

		<!-- 弹窗, 新增 / 修改 -->
		<add-or-update ref="addOrUpdateRef" @refreshDataList="getDataList" @openFind="open()"></add-or-update>
	</el-card>
</template>

<script setup lang="ts" name="AttendanceShiftIndex">
import { useCrud } from '@/hooks'
import { h, reactive, ref } from 'vue'
import { IHooksOptions } from '@/hooks/interface'
import AddOrUpdate from './plane/template-a-u.vue'

const state: IHooksOptions = reactive({
	dataListUrl: '/nb/shift/page',
	deleteUrl: '/nb/shift/delete',
	queryForm: {}
})
const dataListLeft = ref()
const refreshTable = ref()
const queryList = ref()
const addOrUpdateRef = ref()
const addOrUpdateHandle = (id?: number) => {
	addOrUpdateRef.value.init(id)
}

const findOrgStaffRef = ref()
const open = () => {
	console.info('1111')
	findOrgStaffRef.value.init()
}
const fn = () => {
	console.info('员工选择 -返现')
}

//处理 roleId 属性
const fnRoleId = (row: { id: string | undefined }) => {
}
//角色添加按键
const addLeftView = () => {
	return h(
		'div',
		{},
		h(
			'svg',
			{ width: '15px', height: '15px' },
			h('use', {
				href: '#icon-setting',
				onClick: () => {
					addOrUpdateHandle()
				}
			})
		)
	)
}

const { getDataList, selectionChangeHandle, sizeChangeHandle, currentChangeHandle, deleteBatchHandle } = useCrud(state)
</script>
